using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter09
{
	/// <summary>
	/// Example07: The Ballistic Pendulum
	/// The ballistic pendulum (Fig.9.11) is an apparatus used 
	/// to measure the speed of a fast moving projectile, such 
	/// as a bullet. A bullet of mass m_1 is fired into a large 
	/// block of wood of mass m_2 suspended from some light wires. 
	/// The bullet embeds in the block, and the entire system 
	/// swings through a height h. How can we determine the speed 
	/// of the bullet from a measurement of h?
	/// v = (m_1+m_2)/m_1*\sqrt{2gh}
	/// </summary>
	public class Example07
	{
		public Example07()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Mass m1 = new L.Mass();
			m1.kg = 0.01;
			L.Mass m2 = new L.Mass();
			m2.kg = 10.0;
			L.Velocity v = new L.Velocity();
			v.XVariableQ = true;
			L.Mass ma = new L.Mass();
			ma.kg = m1.kg + m2.kg;
			L.Length h = new L.Length();
			h.m = 0.1;
			L.Work W = new L.Work();
			W.J = - ma.kg*L.Constant.AccelerationOfGravity*h.m;
			L.KineticEnergy Ki = new L.KineticEnergy();
			Ki.VariableQ = true;
			L.KineticEnergy Kf = new L.KineticEnergy();
			Kf.J = 0.0;
			L.FundamentalLaw.WorkEnergyTheorem(Ki,W,Kf);
			L.Velocity V = new L.Velocity(ma,Ki);
		    L.Momentum[] pi= new L.Momentum[1];
			pi[0] = new L.Momentum(m1,v);
		    L.Momentum[] pf= new L.Momentum[1];
			pf[0] = new L.Momentum(ma,V);
			L.FundamentalLaw.MomentumConservation(pi,pf);
			v.X = pi[0].X/m1.kg;
			result += Convert.ToString(v.X)+"\r\n";
			result += Convert.ToString((m1.kg+m2.kg)/m1.kg*V.X);
		}
	}
}
